package com.resource.project.controller.system;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.resource.project.entity.system.Hr;
import com.resource.project.entity.RespBean;
import com.resource.project.os.HrVo;
import com.resource.project.service.system.service.IHrService;
import com.resource.util.page.PageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author resource
 * @since 2020-03-14
 */
@RestController
@RequestMapping("/project/hr")
@Api(tags = "用户管理")
public class HrController {
    @Autowired
    private IHrService iHrService;
    @ApiOperation(value = "用户分页")
    @PostMapping
    public IPage<HrVo> page(PageParam pageParam, @RequestBody Hr hr){
        return iHrService.page(pageParam,hr);
    }

    @ApiOperation(value = "用户个人信息展示")
    @GetMapping("/userInfo")
    public RespBean userInfo(){
        return iHrService.userInfo();
    }

    @ApiOperation(value = "管理员添加用户，和用户注册都可调用此接口")
    @PostMapping("/add")
    public RespBean add(@RequestBody Hr hr){
        return iHrService.hrReg(hr);
    }

    @ApiOperation(value = "修改用户")
    @PutMapping
    public RespBean update(@RequestBody Hr hr){
        return iHrService.updateHr(hr);
    }

    @ApiOperation(value = "修改个人基本信息")
    @PostMapping("/updateBasic")
    public RespBean updateBasic(@RequestBody Hr hr){
        return iHrService.updateHr(hr);
    }

    @ApiOperation(value = "忘记密码")
    @GetMapping("/forget")
    public RespBean forgetPassword(String email){
        return iHrService.forgetPassword(email);
    }

    @ApiOperation(value = "重置密码")
    @PostMapping("/reset")
    public RespBean resetPassword(@RequestBody Hr hr){
        return iHrService.resetPassword(hr);
    }

    @ApiOperation(value = "启用禁用，用户,此处是将用户禁用")
    @DeleteMapping
    public RespBean deleteOne(Long id,Boolean flag){
        if (iHrService.update(id,flag)){
            return RespBean.ok();
        }
        return RespBean.error();
    }
}
